package com.example.controller.frontend;

import com.example.common.ApiResult;
import com.example.service.CollectService;
import com.example.vo.CollectVO;
import com.example.vo.VideoDatabaseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/api/frontend/collect")
@Api(tags = "收藏管理")
public class FrontendCollectController {

    @Resource
    private CollectService collectService;


    /**
     * 课程收藏
     * @param courseId
     * @return
     */
    @PutMapping("/collectCourse/{courseId}")
    @ApiOperation("课程收藏")
    public ApiResult collectCourse(@PathVariable Integer courseId){
        Integer integer = collectService.collectCourse(courseId);
        if (integer == 1){
            return ApiResult.ok(integer);
        }else {
            return ApiResult.fail("收藏课程失败！");
        }
    }


    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    @ApiOperation("根据id删除")
    public ApiResult deleteCollect(@RequestParam Integer id){
        boolean b = collectService.removeById(id);
        return ApiResult.ok(b,"删除成功！");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteBatch")
    @ApiOperation("批量删除")
    public ApiResult deleteCollectBatch(@RequestBody Integer[] ids){
        boolean b = collectService.removeBatchByIds(Arrays.asList(ids));
        return ApiResult.ok(b,"批量删除成功！");
    }



    /**
     * 查询收藏表单
     * @param userId
     * @return
     */
    @GetMapping("/select/{userId}")
    @ApiOperation("查询收藏表单")
    public ApiResult selectCollectList(@PathVariable Integer userId){
        List<CollectVO> collectList = collectService.selectCollectList(userId);
        return ApiResult.ok(collectList);
    }

    /**
     * 视频库页面
     * @param majorId
     * @return
     */
    @GetMapping("/selectVd/{majorId}")
    @ApiOperation("视频库页面")
    public ApiResult selectVideoDatabase(@PathVariable Integer majorId){
        List<VideoDatabaseVO> videoDatabaseVOS = collectService.selectVideoDatabase(majorId);
        return ApiResult.ok(videoDatabaseVOS);
    }
}
